﻿#region Using Directives

    using System;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.BusinessLogic.Common.Criteria;

#endregion

namespace MarketPulse.BusinessLogic.Common
{
    /// <summary>
    /// This class represents a read only instance of a Branch within the system.
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.BranchFactory, MarketPulse.DataAccess.Factory", "FetchInfo")]
    public class BranchInfo : MarketPulseReadOnlyBase<BranchInfo>
    {

        #region Member Variables

            #region Association GUID Member Variables (Foreign Keys)

                /// <summary>
                /// The Guid of the company (BusinessObject) that this Branch belongs to 
                /// </summary>
                public static PropertyInfo<Nullable<Guid>> mCompanyGuidProperty = RegisterProperty<Nullable<Guid>>(p => p.CompanyGuid);
                /// <summary>
                /// The Guid of the area (BusinessObject) that this Branch is in
                /// </summary>
                public static PropertyInfo<Nullable<Guid>> mAreaGuidProperty = RegisterProperty<Nullable<Guid>>(p => p.AreaGuid);
                /// <summary>
                /// The corresponding Legacy ID for this Branch (from legacy database)
                /// </summary>
                public static PropertyInfo<long> mLegacyBranchIdProperty = RegisterProperty<long>(p => p.LegacyBranchId);

            #endregion

            /// <summary>
            /// A human readable name for this Branch
            /// </summary>
            public static PropertyInfo<string> mBranchNameProperty = RegisterProperty<string>(p => p.Name);

            /// <summary>
            /// A human readable Building name or number for this Branch
            /// </summary>
            public static PropertyInfo<string> mBuildingNameOrNumberProperty = RegisterProperty<string>(p => p.BuildingNameOrNumber);

            /// <summary>
            /// A human readable Address line (number 1 of 5) for this Branch
            /// </summary>
            public static PropertyInfo<string> mAddressLine1Property = RegisterProperty<string>(p => p.AddressLine1);

            /// <summary>
            /// A human readable Address line (number 2 of 5) for this Branch
            /// </summary>
            public static PropertyInfo<string> mAddressLine2Property = RegisterProperty<string>(p => p.AddressLine2);

            /// <summary>
            /// A human readable Address line (number 3 of 5) for this Branch
            /// </summary>
            public static PropertyInfo<string> mAddressLine3Property = RegisterProperty<string>(p => p.AddressLine3);

            /// <summary>
            /// A human readable Address line (number 4 of 5) for this Branch
            /// </summary>
            public static PropertyInfo<string> mAddressLine4Property = RegisterProperty<string>(p => p.AddressLine4);

            /// <summary>
            /// A human readable Address line (number 5 of 5) for this Branch
            /// </summary>
            public static PropertyInfo<string> mAddressLine5Property = RegisterProperty<string>(p => p.AddressLine5);

            /// <summary>
            /// A human readable Postal Code for this Branch
            /// </summary>
            public static PropertyInfo<string> mPostCodeProperty = RegisterProperty<string>(p => p.PostCode);

            /// <summary>
            /// A general memo field for this Branch
            /// </summary>
            public static PropertyInfo<string> mMemoProperty = RegisterProperty<string>(p => p.Memo);

            /// <summary>
            /// The latitude position of this Branch
            /// </summary>
            public static PropertyInfo<double> mLatitudeProperty = RegisterProperty<double>(p => p.Latitude);

            /// <summary>
            /// The longtitude position of this Branch
            /// </summary>
            public static PropertyInfo<double> mLongtitudeProperty = RegisterProperty<double>(p => p.Longtitude);

            #region Association Properties (Related Objects)

                /// <summary>
                /// The list of (Read Only) Branch Attributes associated with this Branch
                /// </summary>
                public static PropertyInfo<BranchAttributeInfoList> mBranchAttributeInfoListProperty = RegisterProperty<BranchAttributeInfoList>(p => p.Attributes);

            #endregion

        #endregion

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private BranchInfo()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// Method used to retrieve a Branch info object 
                /// </summary>
                /// <param name="guid">The guid of the Branch info object to retrieve</param>
                /// <returns>The populated Branch info object survey</returns>
                public static BranchInfo Get(Guid guid)
                {
                    return DataPortal.Fetch<BranchInfo>(new SingleCriteria<Guid>(guid));
                }

                /// <summary>
                /// Method used to retrieve a Branch info object 
                /// </summary>
                /// <param name="guid">The guid of the Branch info object to retrieve</param>
                /// <returns>The populated Branch info object survey</returns>
                public static BranchInfo GetByGuid(Guid guid)
                {
                    return DataPortal.Fetch<BranchInfo>(new SingleCriteria<Guid>(guid));
                }

                /// <summary>
                /// Method used to retrieve a Branch info object 
                /// </summary>
                /// <param name="visitGuid">The guid of the Visit associated with the BranchInfo object to retrieve</param>
                /// <returns>The populated Branch info object</returns>
                public static BranchInfo GetByVisitGUID(Guid visitGuid)
                {
                    return DataPortal.Fetch<BranchInfo>(new VisitGUIDCriteria(visitGuid));
                }

            #endregion

        #endregion

        #region Properties

            #region Association GUID Properties (Foreign Keys)

                /// <summary>
                /// The GUID of the company (BusinessObject) that this Branch belongs to 
                /// </summary>
                public Nullable<Guid> CompanyGuid { get { return GetProperty(mCompanyGuidProperty); } }

                /// <summary>
                /// The GUID of the area (BusinessObject) that this Branch is in
                /// </summary>
                public Nullable<Guid> AreaGuid { get { return GetProperty(mAreaGuidProperty); } }

                /// <summary>
                /// The corresponding Legacy ID for this Branch (from legacy database)
                /// </summary>
                public long LegacyBranchId { get { return GetProperty(mLegacyBranchIdProperty); } }

            #endregion

            /// <summary>
            /// A human readable name for this Branch
            /// </summary>
            public string Name { get { return GetProperty(mBranchNameProperty); } }

            /// <summary>
            /// A human readable Building name or number
            /// </summary>
            public string BuildingNameOrNumber { get { return GetProperty(mBuildingNameOrNumberProperty); } }

            /// <summary>
            /// A human readable Address line (number 1 of 5)
            /// </summary>
            public string AddressLine1 { get { return GetProperty(mAddressLine1Property); } }

            /// <summary>
            /// A human readable Address line (number 2 of 5)
            /// </summary>
            public string AddressLine2 { get { return GetProperty(mAddressLine2Property); } }

            /// <summary>
            /// A human readable Address line (number 3 of 5)
            /// </summary>
            public string AddressLine3 { get { return GetProperty(mAddressLine3Property); } }

            /// <summary>
            /// A human readable Address line (number 4 of 5)
            /// </summary>
            public string AddressLine4 { get { return GetProperty(mAddressLine4Property); } }

            /// <summary>
            /// A human readable Address line (number 5 of 5)
            /// </summary>
            public string AddressLine5 { get { return GetProperty(mAddressLine5Property); } }

            /// <summary>
            /// A human readable Postal Code
            /// </summary>
            public string PostCode { get { return GetProperty(mPostCodeProperty); } }

            /// <summary>
            /// A general memo field
            /// </summary>
            public string Memo { get { return GetProperty(mMemoProperty); } }

            /// <summary>
            /// The latitude position of this Branch
            /// </summary>
            public double Latitude { get { return GetProperty(mLatitudeProperty); } }

            /// <summary>
            /// The longtitude position of this Branch
            /// </summary>
            public double Longtitude { get { return GetProperty(mLongtitudeProperty); } }

            #region Association Properties (Related Objects)

                /// <summary>
                /// The list of (Read Only) Branch Attributes associated with this Branch
                /// </summary>
                public BranchAttributeInfoList Attributes
                {
                    get
                    {
                        // If the property hasn't been loaded yet
                        if (!FieldManager.FieldExists(mBranchAttributeInfoListProperty))
                        {
                            LoadProperty(mBranchAttributeInfoListProperty, BranchAttributeInfoList.Get(GUID.Value));
                            OnPropertyChanged(mBranchAttributeInfoListProperty);
                            return ReadProperty(mBranchAttributeInfoListProperty);
                        }
                        else
                        {
                            // Return the current property
                            return GetProperty(mBranchAttributeInfoListProperty);
                        }
                    }
                }

            #endregion

        #endregion
    }
}
